<template>
  <el-cascader :value="value" size="mini" :props="props" :options="depts" separator="-" @change="changeValue" />
</template>

<script>
import { getDepartment } from '@/api/department'
import { tranlateListTree } from '@/utils'

export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      depts: [],
      props: {
        value: 'id',
        label: 'name'
      }

    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      const res = await getDepartment()
      // console.log(res)
      this.depts = tranlateListTree(res, 0)
    },
    changeValue(list) {
      if (list.length) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style scoped lang='scss'>

</style>
